﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Utilities.Xna.Framework.Graphics;

namespace SceneManager.Processors
{
    public class DefaultRenderProcessor : EffectProcessor, IFinalRenderer
    {
        public DefaultRenderProcessor(Game game) : base(game, "Shaders/Default/Render")
        {
        }

        public override void Process(Camera camera, GameTime gameTime)
        {
            Effect.Parameters["CameraPosition"].SetValue(camera.Position);
            Effect.Parameters["FrustumCorners"].SetValue(camera.FrustumCorners);

            base.Process(camera, gameTime);
        }

        public Texture2D Render(Camera camera, GameTime gameTime, RenderType renderType)
        {
            if (renderType == RenderType.ToScreen)
                Game.GraphicsDevice.SetRenderTarget(null);
            else
                Game.GraphicsDevice.SetRenderTarget(Outputs["Output"]);

            Game.GraphicsDevice.Clear(Color.Black);
            Process(camera, gameTime);

            if (renderType == RenderType.ToScreen)
                return null;
            else
                return Outputs["Output"];
        }
    }
}
